package com.zy.dom4j.example;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * Created by Allen on 2017/3/13.
 */
public class CreateDocument {

    public Document create() {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement( "root" );

        Element author1 = root.addElement( "author" )
                .addAttribute( "name", "中文" )
                .addAttribute( "location", "UK" )
                .addText( "James Strachan" );

        Element author2 = root.addElement( "author" )
                .addAttribute( "name", "Bob" )
                .addAttribute( "location", "US" )
                .addText( "Bob McWhirter" );

        return document;
    }

}
